<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>2048</title>
    <script type="text/javascript" src="../../js/2048.js"></script>
    <link rel="stylesheet" href="../../css/all.css">
    <jsp:useBean id="user" class="gamer.Bean.User" scope="session"/>
</head>
<body class="container">
<div>
    <div class="header">
        <img class="logo-img" src="../../img/logo.png" alt="logo">
        <div class="menu-div">
            <ul>
                <li><a href="../../index.jsp">首页</a></li>
                <li style="background-color: #BBB"><a href="gameMenu.jsp">游戏菜单</a></li>
                <%
                    if (user.getUser() == null)
                        out.print("<li><a href=\"../user/login.jsp\">登录</a></li>");
                    else
                        out.print("<li><a href=\"../user/userInfo.jsp\">用户中心</a></li>");
                %>
            </ul>
        </div>
    </div>
    <div class="main-div">
        <h3>2048当前得分：<span id="score">0</span></h3>
        <div class="from-div">
            <div>
                <% for (int i = 0; i < 4; i++) { %>
                <div class="row">
                    <% for (int j = 0; j < 4; j++) { %>
                    <div class="cell container" id="cell_<%=i%>_<%=j%>"></div>
                    <% } %>
                </div>
                <% } %>
            </div>
        </div>
        <button id="restartButton" onclick="initGame()">开始</button>
    </div>
</div>
<script>
    document.addEventListener('keydown', function (e) {
        switch (e.keyCode) {
            case 37:
                moveLeft();
                break; // 左
            case 38:
                moveUp();
                break;   // 上
            case 39:
                moveRight();
                break; // 右
            case 40:
                moveDown();
                break;  // 下
        }
        if (canMove()) {
            addRandomNumber();
        } else {
            alert("Game Over!");
        }
        checkWin();
        updateView();
    });
</script>
</body>
</html>
